
<?php
include_once 'AddArticlePresenter.php';
include_once 'AbstractView.php';
include_once 'InsultBuilder.php';
class AddArticleView extends AbstractView {
	private $presenter;
	public function __construct() {
		parent::__construct ();
		$this->presenter = new AddArticlePresenter ( $this, parent::getContentRepository () );
	}
	public function addArticleFailed($reason) {
		$builder = new InsultBuilder ();
		$builder->setMessage ( $reason )->setTitle ( "I hope you spent a lot of time on article!" )->setPicture ( "addarticle_failed.jpg" )->setSource ( "addarticle.php" );
		parent::redirect ( $builder->build () );
	}
	public function addArticleSucceed($articleId) {
		$builder = new InsultBuilder ();
		$builder->setMessage ( "You are the champion, my friend! And you'll keep on douching till the end." )->setTitle ( "All right." )->setPicture ( "addarticle_succeed.jpg" )->setSource ( "readarticle.php?article=" . $articleId );
		parent::redirect ( $builder->build () );
	}
	public function render() {
		if (! parent::invokedByAdmin ()) {
			parent::block ();
			return;
		}
		
		if (isset ( $_POST ["title"] ) || isset ( $_POST ["content"] )) {
			
			$this->presenter->postArticle ( $_POST ["title"], $_POST ["content"], parent::getActiveUser ()->getuserName () );
			return;
		}
		
		require 'AddArticle.phtml';
	}
}

$view = new AddArticleView ();
$view->render ();

